<?php

/**
 * This is the model class for table "silt_lamp_exam".
 *
 * The followings are the available columns in table 'silt_lamp_exam':
 * @property integer $id
 * @property string $cornea_od
 * @property string $cornea_os
 * @property string $ac_od
 * @property string $ac_os
 * @property string $iris_od
 * @property string $iris_os
 * @property string $lens_od
 * @property string $lens_os
 * @property string $vitreous_od
 * @property string $vitreous_os
 * @property integer $rx_id
 * @property integer $personalinfo_id
 *
 * The followings are the available model relations:
 * @property Rx $rx
 * @property PersonalInformation $personalinfo
 */
class SiltLampExam extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return SiltLampExam the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'silt_lamp_exam';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('rx_id, personalinfo_id', 'numerical', 'integerOnly'=>true),
			array('cornea_od, cornea_os, ac_od, ac_os, iris_od, iris_os, lens_od, lens_os, vitreous_od, vitreous_os', 'length', 'max'=>5),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, cornea_od, cornea_os, ac_od, ac_os, iris_od, iris_os, lens_od, lens_os, vitreous_od, vitreous_os, rx_id, personalinfo_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rx' => array(self::BELONGS_TO, 'Rx', 'rx_id'),
			'personalinfo' => array(self::BELONGS_TO, 'PersonalInformation', 'personalinfo_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'cornea_od' => 'Cornea Od',
			'cornea_os' => 'Cornea Os',
			'ac_od' => 'Ac Od',
			'ac_os' => 'Ac Os',
			'iris_od' => 'Iris Od',
			'iris_os' => 'Iris Os',
			'lens_od' => 'Lens Od',
			'lens_os' => 'Lens Os',
			'vitreous_od' => 'Vitreous Od',
			'vitreous_os' => 'Vitreous Os',
			'rx_id' => 'Rx',
			'personalinfo_id' => 'Patient Name',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('cornea_od',$this->cornea_od,true);
		$criteria->compare('cornea_os',$this->cornea_os,true);
		$criteria->compare('ac_od',$this->ac_od,true);
		$criteria->compare('ac_os',$this->ac_os,true);
		$criteria->compare('iris_od',$this->iris_od,true);
		$criteria->compare('iris_os',$this->iris_os,true);
		$criteria->compare('lens_od',$this->lens_od,true);
		$criteria->compare('lens_os',$this->lens_os,true);
		$criteria->compare('vitreous_od',$this->vitreous_od,true);
		$criteria->compare('vitreous_os',$this->vitreous_os,true);
		$criteria->compare('rx_id',$this->rx_id);
		$criteria->compare('personalinfo_id',$this->personalinfo_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public function getFName()
        {       
        return $this->personal_information['FullName']; 
        }
}